#include <windows.h>
#include "CCharHealthPacket.h"
#include "CUtil.h"

CCharHealthPacket::CCharHealthPacket(CBaseEntity * schar) {

	this->type			= 0xDF;
	this->size			= 0x0E;

	memset(this->data, 0, 0x0e*2-4);
	memcpy(this->data+4-4, &(schar->m_id), 4);
	memcpy(this->data+8-4, &(schar->h.hp), 2);
	if((((CChar*)schar)->getMaxMp()) <= 0) {
		schar->h.mp = 0;
	}
	memcpy(this->data+12-4, &(schar->h.mp), 2);
	memcpy(this->data+16-4, &(schar->h.tp), 2);

	unsigned short targId = schar->getTargId();
	memcpy(this->data+0x14-4, &targId, 2);
	this->data[0x16-4] = (unsigned char) CUtil::round(((float)schar->getHp() / (float)(((CChar*)schar)->getMaxHp())) * 100);
	this->data[0x17-4] = (unsigned char) CUtil::round(((float)schar->getMp() / (float)(((CChar*)schar)->getMaxMp())) * 100);


}

CCharHealthPacket::~CCharHealthPacket() {

}